package com.git.mapper;

import java.util.ArrayList;
import java.util.List;

import com.git.domain.UserEntity;

public class UserDao {
	public UserEntity getDatabase(String username) {
		List<UserEntity> users = internalDatabase();

		for (UserEntity user : users) {
			if (user.getUsername().equals(username) == true) {
				return user;
			}
		}
		return null;
	}

	/**
	 * 模拟是从数据库中查出的数据
	 */
	private List<UserEntity> internalDatabase() {

		List<UserEntity> users = new ArrayList<UserEntity>();
		UserEntity user = null;

		// (admin:admin)
		user = new UserEntity();
		user.setUsername("admin");
		user.setPassword("21232f297a57a5a743894a0e4a801fc3");
		user.setAccess(1);
		users.add(user);

		// (user:user)
		user = new UserEntity();
		user.setUsername("user");
		user.setPassword("ee11cbb19052e40b07aac0ca060c23ee");
		user.setAccess(2);
		users.add(user);

		return users;
	}
}

